﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.Prism.Events;
using Sample.Events;
using Sample.Interfaces;

namespace Sample.Modules.MainContent.ViewModels
{
    public class MainContentViewModel
    {
        private readonly ILibrary _library;
        private readonly IEventAggregator _eventAggregator;

        public MainContentViewModel(ILibrary library, IEventAggregator eventAggregator)
        {
            if (library == null)
            {
                throw new ArgumentNullException("library");
            }
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }
            _library = library;
            _eventAggregator = eventAggregator;
        }

        public IList<IBook> ItemsSource
        {
            get
            {
                return _library.Books;
            }
        }

        public void ItemDoubleClicked(IBook item)
        {
            _eventAggregator.GetEvent<OpenItemEvent>().Publish(item);
        }
    }
}
